package com.xyht.sca_s.student_manage_system.modules.walkThrough.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.walkThrough.entity.dto.SmsWalkThroughAddDto;
import com.xyht.sca_s.student_manage_system.modules.walkThrough.entity.dto.SmsWalkThroughApprovalDto;
import com.xyht.sca_s.student_manage_system.modules.walkThrough.service.SmsWalkThroughService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-02-12
 */
@RestController
@RequestMapping("/walkThrough")
@SecretBody
public class SmsWalkThroughController {
    //todo 还未写流程功能,只是固定只有辅导员能审核
    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Autowired
    private SmsWalkThroughService smsWalkThroughService;

    @ApiModelProperty(value = "走读申请")
    @PostMapping("/student/add")
    public ResponseResult addWalkThroughProcess(@RequestBody SmsWalkThroughAddDto smsWalkThroughAddDto, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWalkThroughService.addWalkThrough(smsWalkThroughAddDto, userId);
    }

    @ApiModelProperty(value = "学生端查看走读申请列表")
    @GetMapping("/student/all")
    public ResponseResult selectWalkThroughList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWalkThroughService.selectWalkThroughList(pageSize,pageNum,userId);
    }

    @ApiModelProperty(value = "查看走读申请详情")
    @GetMapping("/id")
    public ResponseResult selectWalkThroughById(String id){
        return smsWalkThroughService.selectWalkThroughById(id);
    }

    @ApiModelProperty(value = "学生端走读申请搜索接口")
    @GetMapping("/student/get")
    public ResponseResult selectStudentWalkThrough(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   HttpServletRequest request,
                                                   String content){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWalkThroughService.selectStudentWalkThrough(pageSize,pageNum,userId,content);
    }
    @ApiModelProperty(value = "教师端审批走读申请")
    @PostMapping("/teacher/approval")
    public ResponseResult approvalWalkThrough(@RequestBody SmsWalkThroughApprovalDto smsWalkThroughApprovalDto
            , HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWalkThroughService.approvalWalkThrough(smsWalkThroughApprovalDto,userId);
    }

    @ApiModelProperty(value = "教师端查看走读审核列表")
    @GetMapping("/teacher/auditList")
    public ResponseResult selectAuditList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWalkThroughService.selectAuditList(pageSize,pageNum,userId);
    }
}

